/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.example.model;

import com.wisnu.example.entity.Ptik;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Wisnu Wardoyo
 */
public class PtikTableModel extends AbstractTableModel {

    List<Ptik> list = new ArrayList<>();

    public void setList(List<Ptik> list) {
        this.list = list;
    }

    public boolean add(Ptik element) {
        try {
            return list.add(element);
        } finally {
            fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
        }
    }

    public Ptik get(int index) {
        return list.get(index);
    }

    public Ptik set(int index, Ptik element) {
        try {
            return list.set(index, element);
        } finally {
            fireTableRowsUpdated(index, index);
        }
    }

    public Ptik remove(int index) {
        try {
            return list.remove(index);
        } finally {
            fireTableRowsDeleted(index, index);
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Id";
            case 1:
                return "NIM";
            case 2:
                return "Nama";
            case 3:
                return "Tanggal Lahir";
            case 4:
                return "Telepon";
            case 5:
                return "Email";
            default:
                return null;
        }
    }

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return 6;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return list.get(rowIndex).getId();
            case 1:
                return list.get(rowIndex).getNim();
            case 2:
                return list.get(rowIndex).getNama();
            case 3:
                return list.get(rowIndex).getTanggalLahir();
            case 4:
                return list.get(rowIndex).getTelepon();
            case 5:
                return list.get(rowIndex).getEmail();
            default:
                return null;
        }
    }

}
